<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>LCOV - self_test2.info - strings/apr_strnatcmp.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">strings</a> - apr_strnatcmp.c<span style="font-size: 80%;"> (source / <a href="apr_strnatcmp.c.func.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">self_test2.info</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">35</td>
            <td class="headerCovTableEntry">55</td>
            <td class="headerCovTableEntryLo">63.6 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2011-07-03</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">3</td>
            <td class="headerCovTableEntry">3</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td></td>
            <td class="headerItem">Branches:</td>
            <td class="headerCovTableEntry">24</td>
            <td class="headerCovTableEntry">54</td>
            <td class="headerCovTableEntryLo">44.4 %</td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">           Branch data     Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>                :            : /* -*- mode: c; c-file-style: &quot;k&amp;r&quot; -*-</a>
<span class="lineNum">       2 </span>                :            : 
<span class="lineNum">       3 </span>                :            :   strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
<span class="lineNum">       4 </span>                :            :   Copyright (C) 2000 by Martin Pool &lt;mbp@humbug.org.au&gt;
<span class="lineNum">       5 </span>                :            : 
<span class="lineNum">       6 </span>                :            :   This software is provided 'as-is', without any express or implied
<span class="lineNum">       7 </span>                :            :   warranty.  In no event will the authors be held liable for any damages
<span class="lineNum">       8 </span>                :            :   arising from the use of this software.
<span class="lineNum">       9 </span>                :            : 
<span class="lineNum">      10 </span>                :            :   Permission is granted to anyone to use this software for any purpose,
<span class="lineNum">      11 </span>                :            :   including commercial applications, and to alter it and redistribute it
<span class="lineNum">      12 </span>                :            :   freely, subject to the following restrictions:
<span class="lineNum">      13 </span>                :            : 
<span class="lineNum">      14 </span>                :            :   1. The origin of this software must not be misrepresented; you must not
<span class="lineNum">      15 </span>                :            :      claim that you wrote the original software. If you use this software
<span class="lineNum">      16 </span>                :            :      in a product, an acknowledgment in the product documentation would be
<span class="lineNum">      17 </span>                :            :      appreciated but is not required.
<span class="lineNum">      18 </span>                :            :   2. Altered source versions must be plainly marked as such, and must not be
<span class="lineNum">      19 </span>                :            :      misrepresented as being the original software.
<span class="lineNum">      20 </span>                :            :   3. This notice may not be removed or altered from any source distribution.
<span class="lineNum">      21 </span>                :            : */
<span class="lineNum">      22 </span>                :            : 
<span class="lineNum">      23 </span>                :            : #include &lt;ctype.h&gt;
<span class="lineNum">      24 </span>                :            : #include &lt;string.h&gt;
<span class="lineNum">      25 </span>                :            : #include &quot;apr_strings.h&quot;
<span class="lineNum">      26 </span>                :            : #include &quot;apr_lib.h&quot;            /* for apr_is*() */
<span class="lineNum">      27 </span>                :            : 
<span class="lineNum">      28 </span>                :            : #if defined(__GNUC__)
<span class="lineNum">      29 </span>                :            : #  define UNUSED __attribute__((__unused__))
<span class="lineNum">      30 </span>                :            : #else
<span class="lineNum">      31 </span>                :            : #  define UNUSED
<span class="lineNum">      32 </span>                :            : #endif
<span class="lineNum">      33 </span>                :            : 
<span class="lineNum">      34 </span>                :            : /* based on &quot;strnatcmp.c,v 1.6 2000/04/20 07:30:11 mbp Exp $&quot; */
<span class="lineNum">      35 </span>                :            : 
<span class="lineNum">      36 </span>                :            : static int
<a name="37"><span class="lineNum">      37 </span>                :            : compare_right(char const *a, char const *b)</a>
<span class="lineNum">      38 </span>                :            : {
<span class="lineNum">      39 </span>                :<span class="lineCov">          1 :      int bias = 0;</span>
<span class="lineNum">      40 </span>                :            :      
<span class="lineNum">      41 </span>                :            :      /* The longest run of digits wins.  That aside, the greatest
<span class="lineNum">      42 </span>                :            :         value wins, but we can't know that it will until we've scanned
<span class="lineNum">      43 </span>                :            :         both numbers to know that they have the same magnitude, so we
<span class="lineNum">      44 </span>                :            :         remember it in BIAS. */
<span class="lineNum">      45 </span>                :<span class="lineCov">          1 :      for (;; a++, b++) {</span>
<span class="lineNum">      46 </span>[<span class="branchCov" title="Branch 1 was taken 1 time"> + </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span>][<span class="branchCov" title="Branch 4 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>]:<span class="lineCov">          2 :           if (!apr_isdigit(*a)  &amp;&amp;  !apr_isdigit(*b))</span>
<span class="lineNum">      47 </span>                :            :                break;
<span class="lineNum">      48 </span>        [<span class="branchCov" title="Branch 1 was taken 1 time"> + </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span>]:<span class="lineCov">          2 :           else if (!apr_isdigit(*a))</span>
<span class="lineNum">      49 </span>                :<span class="lineCov">          1 :                return -1;</span>
<span class="lineNum">      50 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 1 time"> + </span>]:<span class="lineCov">          1 :           else if (!apr_isdigit(*b))</span>
<span class="lineNum">      51 </span>                :<span class="lineNoCov">          0 :                return +1;</span>
<span class="lineNum">      52 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">          1 :           else if (*a &lt; *b) {</span>
<span class="lineNum">      53 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                if (!bias)</span>
<span class="lineNum">      54 </span>                :<span class="lineNoCov">          0 :                     bias = -1;</span>
<span class="lineNum">      55 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :           } else if (*a &gt; *b) {</span>
<span class="lineNum">      56 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :                if (!bias)</span>
<span class="lineNum">      57 </span>                :<span class="lineCov">          1 :                     bias = +1;</span>
<span class="lineNum">      58 </span>[<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>][<span class="branchNoExec" title="Branch 2 was not executed"> # </span><span class="branchNoExec" title="Branch 3 was not executed"> # </span>]:<span class="lineNoCov">          0 :           } else if (!*a  &amp;&amp;  !*b)</span>
<span class="lineNum">      59 </span>                :            :                break;
<span class="lineNum">      60 </span>                :            :      }
<span class="lineNum">      61 </span>                :            : 
<span class="lineNum">      62 </span>                :<span class="lineNoCov">          0 :      return bias;</span>
<span class="lineNum">      63 </span>                :            : }
<span class="lineNum">      64 </span>                :            : 
<span class="lineNum">      65 </span>                :            : 
<span class="lineNum">      66 </span>                :            : static int
<span class="lineNum">      67 </span>                :            : compare_left(char const *a, char const *b)
<span class="lineNum">      68 </span>                :            : {
<span class="lineNum">      69 </span>                :            :      /* Compare two left-aligned numbers: the first to have a
<span class="lineNum">      70 </span>                :            :         different value wins. */
<span class="lineNum">      71 </span>                :<span class="lineNoCov">          0 :      for (;; a++, b++) {</span>
<span class="lineNum">      72 </span>[<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>][<span class="branchNoExec" title="Branch 4 was not executed"> # </span><span class="branchNoExec" title="Branch 5 was not executed"> # </span>]:<span class="lineNoCov">          0 :           if (!apr_isdigit(*a)  &amp;&amp;  !apr_isdigit(*b))</span>
<span class="lineNum">      73 </span>                :            :                break;
<span class="lineNum">      74 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :           else if (!apr_isdigit(*a))</span>
<span class="lineNum">      75 </span>                :<span class="lineNoCov">          0 :                return -1;</span>
<span class="lineNum">      76 </span>        [<span class="branchNoExec" title="Branch 1 was not executed"> # </span><span class="branchNoExec" title="Branch 2 was not executed"> # </span>]:<span class="lineNoCov">          0 :           else if (!apr_isdigit(*b))</span>
<span class="lineNum">      77 </span>                :<span class="lineNoCov">          0 :                return +1;</span>
<span class="lineNum">      78 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :           else if (*a &lt; *b)</span>
<span class="lineNum">      79 </span>                :<span class="lineNoCov">          0 :                return -1;</span>
<span class="lineNum">      80 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :           else if (*a &gt; *b)</span>
<span class="lineNum">      81 </span>                :<span class="lineNoCov">          0 :                return +1;</span>
<span class="lineNum">      82 </span>                :            :      }
<span class="lineNum">      83 </span>                :            :           
<span class="lineNum">      84 </span>                :<span class="lineNoCov">          0 :      return 0;</span>
<span class="lineNum">      85 </span>                :            : }
<span class="lineNum">      86 </span>                :            : 
<span class="lineNum">      87 </span>                :            : 
<span class="lineNum">      88 </span>                :            : static int strnatcmp0(char const *a, char const *b, int fold_case)
<span class="lineNum">      89 </span>                :<span class="lineCov">          7 : {</span>
<span class="lineNum">      90 </span>                :            :      int ai, bi;
<span class="lineNum">      91 </span>                :            :      char ca, cb;
<span class="lineNum">      92 </span>                :            :      int fractional, result;
<span class="lineNum">      93 </span>                :<span class="lineCov">          7 :      ai = bi = 0;</span>
<span class="lineNum">      94 </span>                :            :      while (1) {
<span class="lineNum">      95 </span>                :<span class="lineCov">         10 :           ca = a[ai]; cb = b[bi];</span>
<span class="lineNum">      96 </span>                :            : 
<span class="lineNum">      97 </span>                :            :           /* skip over leading spaces or zeros */
<span class="lineNum">      98 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 10 times"> + </span>]:<span class="lineCov">         10 :           while (apr_isspace(ca))</span>
<span class="lineNum">      99 </span>                :<span class="lineNoCov">          0 :                ca = a[++ai];</span>
<span class="lineNum">     100 </span>                :            : 
<span class="lineNum">     101 </span>        [<span class="branchNoCov" title="Branch 1 was not taken"> - </span><span class="branchCov" title="Branch 2 was taken 10 times"> + </span>]:<span class="lineCov">         10 :           while (apr_isspace(cb))</span>
<span class="lineNum">     102 </span>                :<span class="lineNoCov">          0 :                cb = b[++bi];</span>
<span class="lineNum">     103 </span>                :            : 
<span class="lineNum">     104 </span>                :            :           /* process run of digits */
<span class="lineNum">     105 </span>[<span class="branchCov" title="Branch 1 was taken 1 time"> + </span><span class="branchCov" title="Branch 2 was taken 9 times"> + </span>][<span class="branchCov" title="Branch 4 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 5 was not taken"> - </span>]:<span class="lineCov">         10 :           if (apr_isdigit(ca)  &amp;&amp;  apr_isdigit(cb)) {</span>
<span class="lineNum">     106 </span>                :<span class="lineCov">          1 :                fractional = (ca == '0' || cb == '0');</span>
<span class="lineNum">     107 </span>                :            : 
<span class="lineNum">     108 </span>        [<span class="branchNoCov" title="Branch 0 was not taken"> - </span><span class="branchCov" title="Branch 1 was taken 1 time"> + </span>]:<span class="lineCov">          1 :                if (fractional) {</span>
<span class="lineNum">     109 </span>        [<span class="branchNoExec" title="Branch 0 was not executed"> # </span><span class="branchNoExec" title="Branch 1 was not executed"> # </span>]:<span class="lineNoCov">          0 :                     if ((result = compare_left(a+ai, b+bi)) != 0)</span>
<span class="lineNum">     110 </span>                :<span class="lineNoCov">          0 :                          return result;</span>
<span class="lineNum">     111 </span>                :            :                } else {
<span class="lineNum">     112 </span>        [<span class="branchCov" title="Branch 0 was taken 1 time"> + </span><span class="branchNoCov" title="Branch 1 was not taken"> - </span>]:<span class="lineCov">          1 :                     if ((result = compare_right(a+ai, b+bi)) != 0)</span>
<span class="lineNum">     113 </span>                :<span class="lineCov">          1 :                          return result;</span>
<span class="lineNum">     114 </span>                :            :                }
<span class="lineNum">     115 </span>                :            :           }
<span class="lineNum">     116 </span>                :            : 
<span class="lineNum">     117 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 7 times"> + </span>]:<span class="lineCov">          9 :           if (!ca &amp;&amp; !cb) {</span>
<span class="lineNum">     118 </span>                :            :                /* The strings compare the same.  Perhaps the caller
<span class="lineNum">     119 </span>                :            :                   will want to call strcmp to break the tie. */
<span class="lineNum">     120 </span>                :<span class="lineCov">          2 :                return 0;</span>
<span class="lineNum">     121 </span>                :            :           }
<span class="lineNum">     122 </span>                :            : 
<span class="lineNum">     123 </span>        [<span class="branchCov" title="Branch 0 was taken 4 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          7 :           if (fold_case) {</span>
<span class="lineNum">     124 </span>                :<span class="lineCov">          4 :                ca = apr_toupper(ca);</span>
<span class="lineNum">     125 </span>                :<span class="lineCov">          4 :                cb = apr_toupper(cb);</span>
<span class="lineNum">     126 </span>                :            :           }
<span class="lineNum">     127 </span>                :            :           
<span class="lineNum">     128 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 5 times"> + </span>]:<span class="lineCov">          7 :           if (ca &lt; cb)</span>
<span class="lineNum">     129 </span>                :<span class="lineCov">          2 :                return -1;</span>
<span class="lineNum">     130 </span>        [<span class="branchCov" title="Branch 0 was taken 2 times"> + </span><span class="branchCov" title="Branch 1 was taken 3 times"> + </span>]:<span class="lineCov">          5 :           else if (ca &gt; cb)</span>
<span class="lineNum">     131 </span>                :<span class="lineCov">          2 :                return +1;</span>
<span class="lineNum">     132 </span>                :            : 
<span class="lineNum">     133 </span>                :<span class="lineCov">          3 :           ++ai; ++bi;</span>
<span class="lineNum">     134 </span>                :<span class="lineCov">         10 :      }</span>
<span class="lineNum">     135 </span>                :            : }
<span class="lineNum">     136 </span>                :            : 
<span class="lineNum">     137 </span>                :            : 
<a name="138"><span class="lineNum">     138 </span>                :            : </a>
<span class="lineNum">     139 </span>                :            : APR_DECLARE(int) apr_strnatcmp(char const *a, char const *b)
<span class="lineNum">     140 </span>                :<span class="lineCov">          3 : {</span>
<span class="lineNum">     141 </span>                :<span class="lineCov">          3 :      return strnatcmp0(a, b, 0);</span>
<span class="lineNum">     142 </span>                :            : }
<span class="lineNum">     143 </span>                :            : 
<span class="lineNum">     144 </span>                :            : 
<a name="145"><span class="lineNum">     145 </span>                :            : /* Compare, recognizing numeric string and ignoring case. */</a>
<span class="lineNum">     146 </span>                :            : APR_DECLARE(int) apr_strnatcasecmp(char const *a, char const *b)
<span class="lineNum">     147 </span>                :<span class="lineCov">          4 : {</span>
<span class="lineNum">     148 </span>                :<span class="lineCov">          4 :      return strnatcmp0(a, b, 1);</span>
<span class="lineNum">     149 </span>                :            : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.9</a></td></tr>
  </table>
  <br>

</body>
</html>
